package com.base.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.base.domain.User;

@Repository("userDao")
public class UserDaoImpl extends GenericDaoImpl<User, Long> implements UserDao {

	private static final long serialVersionUID = 1L;

	@Override
	public User getByName(String name) {
		
		Session session = getSessionFactory().getCurrentSession();
		Criteria criteria = session.createCriteria(getEntityClass());
		
		criteria.add(Restrictions.eq("name", name));
		
		@SuppressWarnings("unchecked")
		List<User> usuarios = criteria.list();
		
		return (User) (usuarios.size() > 0 ?  criteria.list().get(0) : null);
	}

	
}